package com.xiemu.ironman.core.rest;

import com.xiemu.ironman.core.service.HotDeployService;
import com.xiemu.ironman.core.utils.ApiUtils;
import com.xiemu.ironman.core.utils.FileUtils;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadJarController {

    @Value("${hot.deploy.jar.file.path}")
    private  String jarAddress;

    @Autowired
 //   @Qualifier("eDsImpl")
    @Qualifier("springDsImpl")
    private HotDeployService hotDeployService;


    @PostMapping(value = "/upload")
    public Object uploadFile(@ApiParam("file") @RequestParam("file") MultipartFile file,
                             @ApiParam("implClassName")  @RequestParam(value = "implClassName",required = false) String implClassName) throws Exception {
        String fileName = FileUtils.write(file, jarAddress);
       // hotDeployService.hotDeploy(fileName,implClassName);
        hotDeployService.hotDeploy(fileName,implClassName);
        return ApiUtils.getApiResult(null);
    }
}
